<?php
// Route serves as a container for specifying a url route
//   that points to a controller and main
class Route {
    private $url = '';
    private $controllerName = '';
    
    public function Route($url, $controllerName) {
        $this->url = $url;
        $this->controllerName = $controllerName;
    }
       
    function getUrl() {
        return $this->url;
    }
    
    function getControllerName() {
        return $this->controllerName;
    }
    
    function parseMethod($url){
    	$rest = substr($url, strlen($this->url) + 1);

    	if(strlen($rest) == 0){
    		return "index";
    	}

    	$bg = 0;
    	$end = strlen($rest);
        
    	if(strrpos($rest, "/")){
    		$end = strrpos($rest, "/");
    	} else if(strrpos($rest, "?")){
    		$end = strrpos($rest, "/");
    	}
    	return substr($rest, $bg, $end);
    }
   
    // Determines whether the specified url matches the route
    // Note: this function can return true for any url that starts
    //   with the route's url property. It is therefore important that
    //   routes be ordered from most specific to least specific in
    //   the index.php page.
    function isMatch($url) {
        if ($this->url == substr($url, 0, strlen($this->url)))        
            return true;
        else
            return false;
    }
}
?>